f9dc9f
@@ -24,6 +24,8 @@
 import java.io.ObjectOutput;
 import java.util.ArrayList;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hive.conf.HiveConf;
 import org.apache.hadoop.hive.ql.exec.MapJoinOperator;
@@ -33,7 +35,6 @@
 import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorUtils;
 import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorUtils.ObjectInspectorCopyOption;
 import org.apache.hadoop.io.Writable;
-
 /**
  * Map Join Object used for both key and value.
  */
@@ -43,6 +44,7 @@
   protected transient RowContainer obj;
   protected transient Configuration conf;
   protected int bucketSize; // bucket size for RowContainer
+  protected Log LOG = LogFactory.getLog(this.getClass().getName());
 
   public MapJoinObjectValue() {
     bucketSize = 100; // default bucket size
@@ -71,7 +73,6 @@
public boolean equals(Object o) {
         }
       }
     }
-
     return false;
   }
 
@@ -90,19 +91,25 @@
public void readExternal(ObjectInput in) throws IOException,
       MapJoinObjectCtx ctx = MapJoinOperator.getMapMetadata().get(
           Integer.valueOf(metadataTag));
       int sz = in.readInt();
+
       RowContainer res = new RowContainer(bucketSize, ctx.getConf());
       res.setSerDe(ctx.getSerDe(), ctx.getStandardOI());
       res.setTableDesc(ctx.getTblDesc());
-      for (int pos = 0; pos < sz; pos++) {
-        Writable val = ctx.getSerDe().getSerializedClass().newInstance();
-        val.readFields(in);
-
-        ArrayList<Object> memObj = (ArrayList<Object>) ObjectInspectorUtils
-            .copyToStandardObject(ctx.getSerDe().deserialize(val), ctx
-            .getSerDe().getObjectInspector(),
-            ObjectInspectorCopyOption.WRITABLE);
-
-        res.add(memObj);
+      if (sz > 0) {
+        int numCols = in.readInt();
+        if (numCols > 0) {
+          for (int pos = 0; pos < sz; pos++) {
+            Writable val = ctx.getSerDe().getSerializedClass().newInstance();
+            val.readFields(in);
+
+            ArrayList<Object> memObj = (ArrayList<Object>) ObjectInspectorUtils
+              .copyToStandardObject(ctx.getSerDe().deserialize(val), ctx
+              .getSerDe().getObjectInspector(),
+               ObjectInspectorCopyOption.WRITABLE);
+
+            res.add(memObj);
+          }
+        }
       }
       obj = res;
     } catch (Exception e) {
@@ -123,10 +130,16 @@
public void writeExternal(ObjectOutput out) throws IOException {
       // Different processing for key and value
       RowContainer<ArrayList<Object>> v = obj;
       out.writeInt(v.size());
-
-      for (ArrayList<Object> row = v.first(); row != null; row = v.next()) {
-        Writable outVal = ctx.getSerDe().serialize(row, ctx.getStandardOI());
-        outVal.write(out);
+      if (v.size() > 0) {
+        ArrayList<Object> row = v.first();
+        out.writeInt(row.size());
+
+        if (row.size() > 0) {
+          for (; row != null; row = v.next()) {
+            Writable outVal = ctx.getSerDe().serialize(row, ctx.getStandardOI());
+            outVal.write(out);
+          }
+        }
       }
     } catch (SerDeException e) {
       throw new IOException(e);
